#include <iostream>
#include <opencv2/core/core.hpp> 
#include<opencv2/highgui/highgui.hpp> 
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main() {
    std::string rtspPath = "rtmp://ns8.indexforce.com/home/mystream";
    VideoCapture cap;
    cap.open(rtspPath);
    if (!cap.isOpened())
    {
        cout << "cannot open video!" << endl;
        return 0;
    }
    VideoWriter writer = VideoWriter("./rtsp-video.avi",//path and filename
        (int)cap.get(CAP_PROP_FOURCC),
        (int)cap.get(CAP_PROP_FPS),
        Size((int)cap.get(CAP_PROP_FRAME_WIDTH),
            (int)cap.get(CAP_PROP_FRAME_HEIGHT)),
        true//colorfull pic
    );
    if (!writer.isOpened()) {
        cout << "create vedio failed!" << endl;
        return 0;
    }
    while (1)
    {
        cv::Mat frame;
        cap >> frame;
        if (frame.empty())
        {
            cout << "frame is empty!" << endl;
            break;
        }      
        cv::Mat img = frame;
        // let's downscale the image using new  width and height
        int down_width = 1080;
        int down_height = 720;
        Mat resized_down;
        //resize down
        resize(img, resized_down, Size(down_width, down_height), INTER_LINEAR);

        cv::imshow("frame", resized_down);
        writer<<img;
        waitKey(1);        
    }  
    return 0;
}